import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import moment from 'moment-timezone';

interface TimeState {
  input: {
    timezone?: string;
    format?: string;
  };
}

describe('MCP Server', () => {
  let server: McpServer;

  beforeEach(() => {
    server = new McpServer({
      name: 'localtime',
      version: '1.0.5',
      capabilities: {
        resources: {},
        tools: {},
      },
    });
  });

  describe('Server Tools', () => {
    it('should register getLocalTime tool', () => {
      const tool = server.tool('getLocalTime', 'Get local time information', {
        input: z.object({
          timezone: z.string().optional(),
          format: z.string().optional()
        })
      }, async (state: TimeState) => {
        const { timezone = 'Asia/Shanghai', format = 'YYYY-MM-DD HH:mm:ss' } = state.input;
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              time: moment().tz(timezone).format(format),
              timezone,
              format
            })
          }]
        };
      });

      expect(tool).toBeDefined();
    });

    it('should register getTimezones tool', () => {
      const tool = server.tool('getTimezones', 'Get available timezones', {
        input: z.object({})
      }, async () => {
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              timezones: moment.tz.names()
            })
          }]
        };
      });

      expect(tool).toBeDefined();
      expect(moment.tz.names().length).toBeGreaterThan(0);
    });
  });
}); 